<?php

class Teacher_AvailableTimeController extends Zend_Controller_Action
{
    public function init()
    {
        /* Initialize action controller here */
    }
//     public function indexAction()
//     {   	
//     	//$_data = $this->getRequest()->getPost();
//     	$frm = new Teacher_Form_FrmAvaliableTime();
//     	$form = $frm->avaliableFilter();
//     	//print_r($form);exit();
//     	$this->view->forms = $form;
    	   	
//     	$db = new Teacher_Model_DbTable_DbAvaliableTime();
//     	$list_time = $db->gettime();
//     	$this->view->listtime = $list_time;
//     }
    public function indexAction()
    {
    	$db = new Application_Model_DbTable_DbGlobal();
    	$sql ="SELECT
					  tvt.`avaliable_id`,
					  tvt.`t_id`,
					  tvt.`academic_year`,
					  tvt.`semester_id`,
					  tvt.`created_date`,
					  t.`teacher_id`,
					  t.`teacher_name`
					FROM
					  `tb_avaliable_time_store` AS tvt,
					  `tbl_teacher` AS t
					 ";
    	if($this->getRequest()->isPost()){
    		$data = $this->getRequest()->getPost();
    		$academic = trim($data["academic"]);
    		if($data["department"]!="" OR $data["department"]!=0){
    			$sql.=" INNER JOIN teach_in AS v_id ON v_id.`teacher_id`=t.`teacher_id` AND v_id.`dpt_id`=".$data["department"];
    		}
    		$sql.=" WHERE t.teacher_name != '' AND t.`teacher_id` = tvt.`t_id`";
    		if($data["semester"]!="" OR $data["semester"]!=0){
    			$sql.=" AND tvt.`semester_id`=".$data["semester"];
    		}
    		if($data["academic"]!="" OR $data["academic"]!=0){
    			$sql.=" AND tvt.`academic_year`='$academic'";
    		}
    		//echo $sql;exit();
    	}else{
    		$sql.=" WHERE t.teacher_name != '' AND t.`teacher_id` = tvt.`t_id`";
    	}
    	 
    	$list_time = $db->getGlobalDb($sql);
    	$this->view->listtime = $list_time;
    	 
    	$frm = new Teacher_Form_FrmAvaliableTime();
    	$form = $frm->avaliableFilter();
    	$this->view->forms = $form;
    	//$this->view->listtime = $list_time;
    	 
    	//     	if($this->getRequest()->isPost()){
    	//     		$data = $this->getRequest()->getPost();
    	//     		print_r($data);
    	// 	    	$db = new Teacher_Model_DbTable_DbAvaliableTime();
    	// 	    	$list_time = $db->gettime($data);
    	// 	    	$this->view->listtime = $list_time;
    	//     	}
    
    }
    public function addAvaliableAction(){
    	//$this->_helper->layout()->disableLayout();
    	if($this->getRequest()->isPost()){
    		$_data = $this->getRequest()->getPost();
    		//print_r($_data);exit();
    		try{
    			$db = new teacher_Model_DbTable_DbAvaliableTime();
    			$sucess = $db->InsertAvaliableTime($_data);
    			print_r($sucess);
    			if($this->getRequest()->getPost("check_7_8_mon")){
    				$insert = $db->check_7_8_mon($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_tur")){
    				$insert = $db->check_7_8_tur($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_wed")){
    				$insert = $db->check_7_8_wed($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_thu")){
    				$insert = $db->check_7_8_thu($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_fri")){
    				$insert = $db->check_7_8_fri($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_sat")){
    				$insert = $db->check_7_8_sat($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_sun")){
    				$insert = $db->check_7_8_sun($_data);
    			}
    			///
    			if($this->getRequest()->getPost("check_8_10_mon")){
    				$insert = $db->check_8_10_mon($_data);
    			}
    			if($this->getRequest()->getPost("check_8_10_tur")){
    				$insert = $db->check_8_10_tur($_data);
    			}
    			if($this->getRequest()->getPost("check_8_10_wed")){
    				$insert = $db->check_8_10_wed($_data);
    			}
    			if($this->getRequest()->getPost("check_8_10_thu")){
    				$insert = $db->check_8_10_thu($_data);
    			}
    			if($this->getRequest()->getPost("check_8_10_fri")){
    				$insert = $db->check_8_10_fri($_data);
    			}
    			if($this->getRequest()->getPost("check_8_10_sat")){
    				$insert = $db->check_8_10_sat($_data);
    			}
    			if($this->getRequest()->getPost("check_8_10_sun")){
    				$insert = $db->check_8_10_sun($_data);
    			}
    			////
    			if($this->getRequest()->getPost("check_10_12_mon")){
    				$insert = $db->check_10_12_mon($_data);
    			}
    			if($this->getRequest()->getPost("check_10_12_tur")){
    				$insert = $db->check_10_12_tur($_data);
    			}
    			if($this->getRequest()->getPost("check_10_12_wed")){
    				$insert = $db->check_10_12_wed($_data);
    			}
    			if($this->getRequest()->getPost("check_10_12_thu")){
    				$insert = $db->check_10_12_thu($_data);
    			}
    			if($this->getRequest()->getPost("check_10_12_fri")){
    				$insert = $db->check_10_12_fri($_data);
    			}
    			if($this->getRequest()->getPost("check_10_12_sat")){
    				$insert = $db->check_10_12_sat($_data);
    			}
    			if($this->getRequest()->getPost("check_10_12_sun")){
    				$insert = $db->check_10_12_sun($_data);
    			}
    			//////
    			if($this->getRequest()->getPost("check_1_2_mon")){
    				$insert = $db->check_1_2_mon($_data);
    			}
    			if($this->getRequest()->getPost("check_1_2_tur")){
    				$insert = $db->check_1_2_tur($_data);
    			}
    			if($this->getRequest()->getPost("check_1_2_wed")){
    				$insert = $db->check_1_2_wed($_data);
    			}
    			if($this->getRequest()->getPost("check_1_2_thu")){
    				$insert = $db->check_1_2_thu($_data);
    			}
    			if($this->getRequest()->getPost("check_1_2_fri")){
    				$insert = $db->check_1_2_fri($_data);
    			}
    			if($this->getRequest()->getPost("check_1_2_sat")){
    				$insert = $db->check_1_2_sat($_data);
    			}
    			if($this->getRequest()->getPost("check_1_2_sun")){
    				$insert = $db->check_1_2_sun($_data);
    			}
    			/////
    			if($this->getRequest()->getPost("check_2_4_mon")){
    				$insert = $db->check_2_4_mon($_data);
    			}
    			if($this->getRequest()->getPost("check_2_4_tur")){
    				$insert = $db->check_2_4_tur($_data);
    			}
    			if($this->getRequest()->getPost("check_2_4_wed")){
    				$insert = $db->check_2_4_wed($_data);
    			}
    			if($this->getRequest()->getPost("check_2_4_thu")){
    				$insert = $db->check_2_4_thu($_data);
    			}
    			if($this->getRequest()->getPost("check_2_4_fri")){
    				$insert = $db->check_2_4_fri($_data);
    			}
    			if($this->getRequest()->getPost("check_2_4_sat")){
    				$insert = $db->check_2_4_sat($_data);
    			}
    			if($this->getRequest()->getPost("check_2_4_sun")){
    				$insert = $db->check_2_4_sun($_data);
    			}
    			//////
    			if($this->getRequest()->getPost("check_4_5_mon")){
    				$insert = $db->check_4_5_mon($_data);
    			}
    			if($this->getRequest()->getPost("check_4_5_tur")){
    				$insert = $db->check_4_5_tur($_data);
    			}
    			if($this->getRequest()->getPost("check_4_5_wed")){
    				$insert = $db->check_4_5_wed($_data);
    			}
    			if($this->getRequest()->getPost("check_4_5_thu")){
    				$insert = $db->check_4_5_thu($_data);
    			}
    			if($this->getRequest()->getPost("check_4_5_fri")){
    				$insert = $db->check_4_5_fri($_data);
    			}
    			if($this->getRequest()->getPost("check_4_5_sat")){
    				$insert = $db->check_4_5_sat($_data);
    			}
    			if($this->getRequest()->getPost("check_4_5_sun")){
    				$insert = $db->check_4_5_sun($_data);
    			}
    			/////
    			if($this->getRequest()->getPost("check_5_7_mon")){
    				$insert = $db->check_5_7_mon($_data);
    			}
    			if($this->getRequest()->getPost("check_5_7_tur")){
    				$insert = $db->check_5_7_tur($_data);
    			}
    			if($this->getRequest()->getPost("check_5_7_wed")){
    				$insert = $db->check_5_7_wed($_data);
    			}
    			if($this->getRequest()->getPost("check_5_7_thu")){
    				$insert = $db->check_5_7_thu($_data);
    			}
    			if($this->getRequest()->getPost("check_5_7_fri")){
    				$insert = $db->check_5_7_fri($_data);
    			}
    			if($this->getRequest()->getPost("check_5_7_sat")){
    				$insert = $db->check_5_7_sat($_data);
    			}
    			if($this->getRequest()->getPost("check_5_7_sun")){
    				$insert = $db->check_5_7_sun($_data);
    			}
    			/////
    			if($this->getRequest()->getPost("check_7_8_1_mon")){
    				$insert = $db->check_7_8_1_mon($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_1_tur")){
    				$insert = $db->check_7_8_1_tur($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_1_wed")){
    				$insert = $db->check_7_8_1_wed($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_1_thu")){
    				$insert = $db->check_7_8_1_thu($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_1_fri")){
    				$insert = $db->check_7_8_1_fri($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_1_sat")){
    				$insert = $db->check_7_8_1_sat($_data);
    			}
    			if($this->getRequest()->getPost("check_7_8_1_sun")){
    				$insert = $db->check_7_8_1_sun($_data);
    			}
    		}catch (Exception $e){
    			echo $e->getMessage();
    		}
    	}
    	$frm = new teacher_Form_FrmAvaliableTime();
    	$form = $frm->addAvaliabletime();
    	$this->view->frmavaliable = $form;
    }
    public function editTimeAction(){
    	$id = $this->getRequest()->getParam("id");
    	$db = new Teacher_Model_DbTable_DbAvaliableTime();
    	$row = $db->getAvailableTimeByID($id);
    	//print_r($row);exit();
    	if($this->getRequest()->isPost()){
    		$data = $this->getRequest()->getPost();
    		$data["id"]= $id;
    		$row = $db->UpdateAvaliableTime($data);
    		
    		////
    		if($this->getRequest()->getPost("check_7_8_mon")){
    			$insert = $db->update_check_7_8_mon($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_tur")){
    			$insert = $db->update_check_7_8_tur($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_wed")){
    			$insert = $db->update_check_7_8_wed($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_thu")){
    			$insert = $db->update_check_7_8_thu($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_fri")){
    			$insert = $db->update_check_7_8_fri($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_sat")){
    			$insert = $db->update_check_7_8_sat($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_sun")){
    			$insert = $db->update_check_7_8_sun($data);
    		}
    		///
    		if($this->getRequest()->getPost("check_8_10_mon")){
    			$insert = $db->update_check_8_10_mon($data);
    		}
    		if($this->getRequest()->getPost("check_8_10_tur")){
    			$insert = $db->update_check_8_10_tur($data);
    		}
    		if($this->getRequest()->getPost("check_8_10_wed")){
    			$insert = $db->update_check_8_10_wed($data);
    		}
    		if($this->getRequest()->getPost("check_8_10_thu")){
    			$insert = $db->update_check_8_10_thu($data);
    		}
    		if($this->getRequest()->getPost("check_8_10_fri")){
    			$insert = $db->update_check_8_10_fri($data);
    		}
    		if($this->getRequest()->getPost("check_8_10_sat")){
    			$insert = $db->update_check_8_10_sat($data);
    		}
    		if($this->getRequest()->getPost("check_8_10_sun")){
    			$insert = $db->update_check_8_10_sun($data);
    		}
    		////
    		if($this->getRequest()->getPost("check_10_12_mon")){
    			$insert = $db->update_check_10_12_mon($data);
    		}
    		if($this->getRequest()->getPost("check_10_12_tur")){
    			$insert = $db->update_check_10_12_tur($data);
    		}
    		if($this->getRequest()->getPost("check_10_12_wed")){
    			$insert = $db->update_check_10_12_wed($data);
    		}
    		if($this->getRequest()->getPost("check_10_12_thu")){
    			$insert = $db->update_check_10_12_thu($data);
    		}
    		if($this->getRequest()->getPost("check_10_12_fri")){
    			$insert = $db->update_check_10_12_fri($data);
    		}
    		if($this->getRequest()->getPost("check_10_12_sat")){
    			$insert = $db->update_check_10_12_sat($data);
    		}
    		if($this->getRequest()->getPost("check_10_12_sun")){
    			$insert = $db->update_check_10_12_sun($data);
    		}
    		//////
    		if($this->getRequest()->getPost("check_1_2_mon")){
    			$insert = $db->update_check_1_2_mon($data);
    		}
    		if($this->getRequest()->getPost("check_1_2_tur")){
    			$insert = $db->update_check_1_2_tur($data);
    		}
    		if($this->getRequest()->getPost("check_1_2_wed")){
    			$insert = $db->update_check_1_2_wed($data);
    		}
    		if($this->getRequest()->getPost("check_1_2_thu")){
    			$insert  = $db->update_check_1_2_thu($data);
    		}
    		if($this->getRequest()->getPost("check_1_2_fri")){
    			$insert = $db->update_check_1_2_fri($data);
    		}
    		if($this->getRequest()->getPost("check_1_2_sat")){
    			$insert = $db->update_check_1_2_sat($data);
    		}
    		if($this->getRequest()->getPost("check_1_2_sun")){
    			$insert = $db->update_check_1_2_sun($data);
    		}
    		/////
    		if($this->getRequest()->getPost("check_2_4_mon")){
    			$insert = $db->update_check_2_4_mon($data);
    		}
    		if($this->getRequest()->getPost("check_2_4_tur")){
    			$insert = $db->update_check_2_4_tur($data);
    		}
    		if($this->getRequest()->getPost("check_2_4_wed")){
    			$insert = $db->update_check_2_4_wed($data);
    		}
    		if($this->getRequest()->getPost("check_2_4_thu")){
    			$insert = $db->update_check_2_4_thu($data);
    		}
    		if($this->getRequest()->getPost("check_2_4_fri")){
    			$insert = $db->update_check_2_4_fri($data);
    		}
    		if($this->getRequest()->getPost("check_2_4_sat")){
    			$insert = $db->update_check_2_4_sat($data);
    		}
    		if($this->getRequest()->getPost("check_2_4_sun")){
    			$insert = $db->update_check_2_4_sun($data);
    		}
    		//////
    		if($this->getRequest()->getPost("check_4_5_mon")){
    			$insert = $db->update_check_4_5_mon($data);
    		}
    		if($this->getRequest()->getPost("check_4_5_tur")){
    			$insert = $db->update_check_4_5_tur($data);
    		}
    		if($this->getRequest()->getPost("check_4_5_wed")){
    			$insert = $db->update_check_4_5_wed($data);
    		}
    		if($this->getRequest()->getPost("check_4_5_thu")){
    			$insert = $db->update_check_4_5_thu($data);
    		}
    		if($this->getRequest()->getPost("check_4_5_fri")){
    			$insert = $db->update_check_4_5_fri($data);
    		}
    		if($this->getRequest()->getPost("check_4_5_sat")){
    			$insert = $db->update_check_4_5_sat($data);
    		}
    		if($this->getRequest()->getPost("check_4_5_sun")){
    			$insert = $db->update_check_4_5_sun($data);
    		}
    		/////
    		if($this->getRequest()->getPost("check_5_7_mon")){
    			$insert = $db->update_check_5_7_mon($data);
    		}
    		if($this->getRequest()->getPost("check_5_7_tur")){
    			$insert = $db->update_check_5_7_tur($data);
    		}
    		if($this->getRequest()->getPost("check_5_7_wed")){
    			$insert = $db->update_check_5_7_wed($data);
    		}
    		if($this->getRequest()->getPost("check_5_7_thu")){
    			$insert = $db->update_check_5_7_thu($data);
    		}
    		if($this->getRequest()->getPost("check_5_7_fri")){
    			$insert = $db->update_check_5_7_fri($data);
    		}
    		if($this->getRequest()->getPost("check_5_7_sat")){
    			$insert = $db->update_check_5_7_sat($data);
    		}
    		if($this->getRequest()->getPost("check_5_7_sun")){
    			$insert = $db->update_check_5_7_sun($data);
    		}
    		/////
    		if($this->getRequest()->getPost("check_7_8_1_mon")){
    			$insert = $db->update_check_7_8_1_mon($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_1_tur")){
    			$insert = $db->update_check_7_8_1_tur($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_1_wed")){
    			$insert = $db->update_check_7_8_1_wed($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_1_thu")){
    			$insert = $db->update_check_7_8_1_thu($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_1_fri")){
    			$insert = $db->update_check_7_8_1_fri($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_1_sat")){
    			$insert = $db->update_check_7_8_1_sat($data);
    		}
    		if($this->getRequest()->getPost("check_7_8_1_sun")){
    			$insert = $db->update_check_7_8_1_sun($data);
    		}
    		$this->_redirect("/teacher/index/");
    	}
    	$frm = new Teacher_Form_FrmAvaliableTime();
    	$form = $frm->addAvaliabletime($row);
    	$this->view->frmavaliable = $form;
    }
 }